package com.srcptit.trainning.toannt.btvn3;
public class bai_7 {
	//chuong trinh kiem tra thoa man de bai
static boolean test(int n){
	int tong=0,k=0,x=0, t=n;
	if(testngto(n)==false)return false;

	while(n!=0){
		k=n%10;
		x=x*10+k;
		tong=tong+k;
		n=n/10;
	}
	if(testfib(tong) && x==t) return true;
	else return false;
}
//kiem tra thoa man day fibonacci
 static boolean testfib(int n){
	int x=0,y=1,z=0;
	while(z<n){
		z=x+y;
		x=y;
		y=z;
	}
	if(z==n) return true;
	else return false;
}
 //kiem tra thoa man so nguyen to
 static boolean testngto(int n){

	 	 for(int i=2;i<=Math.sqrt(n);i++){
	 		 if(n%i==0)
	 			 return false;
	 	 }
	 	 return true;
 }
 //chuong trinh chinh
 public static void main(String[]args){
	 int dem=0;
	 System.out.println("ket qua cua chuong trinh:");
	 for(int i=10000;i<=9999999;i++){
		 if(test(i)){
			 System.out.println(i);
			 dem++;}
	 }
	 System.out.println("Co "+dem+" so thoa man.");
 }
}
